﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SituationManager.aspx.cs" Inherits="Score_Education_AreaManage_SituationManager" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>局级考试管理</title>
<link href="../../Common/css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../Common/Js/jquery.js"></script>
<script type="text/javascript" src="../../Common/Js/common.js"></script>
<script type="text/javascript" src="../../Common/Js/msg.js"></script>
<script type="text/javascript">
var editRow = null;

var cookieName = "openedEduExam";
var openedExamId = null;

function Load()
{
    var yearObj =  document.getElementById('selYear'); 
    if(yearObj != null)
    {   
        for(var i = 0; i < yearObj.options.length;i++)
        {
            var option = yearObj.options[i];
            
            if(Number(option.value) == Number("<%=currSchoolYear%>"))
            {
                option.selected  = "selected";
                document.getElementById('txtYear').value = "<%=currSchoolYear%>"; 
            }
            else
                 option.selected  = false;
        }
    }
    
    var termObj =  document.getElementById('selTerm'); 
    if(termObj != null)
    {    
        for(var i = 0; i < termObj.options.length;i++)
        {
            var option = termObj.options[i];
            
            if(Number(option.value) == Number("<%=currTerm%>"))
            {
                option.selected  = "selected";
                 document.getElementById('txtTerm').value = "<%=currTerm%>";     
            }
            else
                 option.selected  = false;
        }
    }
    
    //若是没有新建权限 则隐藏按钮
    var obj = document.getElementById('btnCreateExam');
    if(parent.useManage == false)
    {
        obj.style.visibility = "hidden";
    }
    else
    {
        obj.style.visibility = "visible";
    }
  //  GetCookie();
}


//弹出删除窗口---------------------------------------------------------------------删除区域
function ShowDelWindow(row)
{
    var examId = row.id;
    showConfirmBox("删除", "确定删除此次考试?", DelExam, examId);
}
//删除方法
function DelExam(examId)
{
    if(examId > 0)
    {
        PageMethods.DelEduExam(examId,function(succ){
               showMassgeBox("提示","删除考试成功",1,null);
               Bind();
           },function(err){
              showMassgeBox("提示",err._message,1,null);
        });
    }
}

//查看申报学校窗口------------------------------------------------------------查看申报学校
function ShowApplyWindow(obj)
{
    InitApplySchool(obj);
    
    ShowPopForm("popTable3", "formTitle3", "查看已提交成绩学校");
    showMask();
}
//初始化申报学校窗口
function InitApplySchool(row)
{
    var appluDoc = self.frames['applySchoolFrame'].document;
    var name = row.cells[0].innerText;
    var nameObj = appluDoc.getElementById('txtExamName');
    if(nameObj != null)
        nameObj.innerText = name; 
       
    var examIdObj = appluDoc.getElementById('txtExamId');
    if(examIdObj != null)
    {
        examIdObj.value = row.id;
    }
    var bindObj = appluDoc.getElementById('btnBind');
    if(bindObj != null)
        bindObj.click();
   // appluDoc.Bind();
}


//修改考试弹出窗口-----------------------------------------------------------------修改区域
function ShowUpdateWindow(obj)
{
   InitUpdateWindow(obj);

   ShowPopForm("popTable2", "formTitle2", "修改局级考试");
   showMask();
}
 
//初始化弹出修改考试窗口的值
function InitUpdateWindow(row)
{
    var updateDoc = self.frames['updateExamFrame'].document;
    
    var name = row.cells[0].innerText;
    var nameObj = updateDoc.getElementById('updateName'); 
    if(nameObj != null)
        nameObj.value = name;
    
    var schoolYear = row.cells[3].schoolYear;//初始化学年
    var yearObj =  updateDoc.getElementById('updateSelYear'); 
    if(yearObj != null)
    {
        for(var i = 0; i < yearObj.options.length;i++)
        {
            var option = yearObj.options[i];
            
            if(Number(option.value) == Number(schoolYear))
                option.selected  = "selected";
            else
                 option.selected  = false;
        }
    }
    
    var term = row.cells[3].id; //初始化学期
    var termObj =  updateDoc.getElementById('updateSelTerm'); 
    if(termObj != null)
    {
        for(var i = 0; i < termObj.options.length;i++)
        {
            var option = termObj.options[i];
            
            if(Number(option.value) == Number(term))
                option.selected  ="selected";
            else
                option.selected  = false;
        }
    }
    
     var grade = row.cells[4].id;//初始化年级
     var gradeObj =  updateDoc.getElementById('updateSelGrade'); 
     if(gradeObj != null)
     {
         for(var i = 0; i < gradeObj.options.length;i++)
         {
             var option = gradeObj.options[i];
             if(Number(option.value) == Number(grade))
                option.selected ="selected";
             else
                option.selected  = false;
         }
     }

     var classType = row.cells[5].id;//初始化分科
     var classTypeObj =  updateDoc.getElementById('updateSelClassType'); 
     if(classTypeObj != null)
     {
         for(var i = 0; i < classTypeObj.options.length;i++)
         {
             var option = classTypeObj.options[i];
             if(Number(option.value) == Number(classType))
                option.selected ="selected";
             else
                option.selected  = false;
         }
     }
     
//     if(grade > 10)
//        classTypeObj.style.display = "block";
//     else
//        classTypeObj.style.display = "none";
     
     var div = updateDoc.getElementById('divSubjects');//初始化科目
     if(div != null)
     {
         var checkItems =  div.getElementsByTagName('INPUT'); 
         var examId = row.id;
         PageMethods.GetSubjectsByExam(examId,function(succ){
                 for(var j=0;j < checkItems.length;j++)
                 {
                     checkItems[j].checked = false;
                 }
                 for(var i=0;i<succ.length;i++)
                 {
                    var subjectId = succ[i]["SubjectID"];
                     for(var j=0;j < checkItems.length;j++)
                     {
                        if(Number(checkItems[j].value) == Number(subjectId))
                        {
                            checkItems[j].checked = "checked";
         
                        }
                     }
                 }
               },function(err){
                  showMassgeBox("提示",err._message,1,null);
            });
      }
      var table = updateDoc.getElementById('updateExamTable');
      table.setAttribute('examId',examId);
}

//------------------------------------------------------------------------------------打开考试
function OpenEduExamWidow(row)
{
    
    showConfirmBox("打开考试", "确定打开此次考试?", OpenExam, row);
}
function OpenExam(row)
{
        
    var examId = row.id;
    var name = row.cells[0].innerText;
    var grade = row.cells[4].id;
    var classType = row.cells[5].id;
    
    //设置cookie 保存打开的学校考试
    PageMethods.SetCookie(examId,name,grade,classType,function(succ){
        var obj = parent.document.getElementById('txtOpenExam');
        if(obj != null)
            obj.innerText =  "打开的考试是："+name;
            
        parent.isExamOpened = examId; 
        Bind(); 
    },function(err){
                  showMassgeBox("提示",err._message,1,null);
            });
   
}


////从cookie里获取打开学校考试
//function GetCookie()
//{ 
//    openedExamName = "<%=GetOpenedExamName()%>";
//    var nameObj = parent.document.getElementById('txtOpenExam'); 
//    if(nameObj != null)
//    {
//        if(openedExamName.length > 0)
//            nameObj.innerText = "当前打开的考试是："+openedExamName;
//        else
//            nameObj.innerText = "当前没有打开的考试";
//    }
//}

//------------------------------------------------------------------------------------下发考试
function ShowPublishedWindow(row)
{
    var examId = row.id;
    showConfirmBox("发布", "下发考试后将不能修改及删除考试信息，确定下发此次考试?", PublishedExam, examId);
}
//下发考试
function PublishedExam(examId)
{
     PageMethods.PublishedExam(examId,function(succ){
            showMassgeBox("提示","下发考试成功",1,null);
            Bind();
     },function(err){
              showMassgeBox("提示",err._message,1,null);
        });
}

//-----------------------------------------------------------------------------------结束考试
function ShowClosedWindow(row)
{
    var examId = row.id;
    showConfirmBox("结束", "确定结束此次考试?", CloseExam, examId);
}
//结束考试
function CloseExam(examId)
{
     PageMethods.CloseEduExam(examId,function(succ){
            showMassgeBox("提示","结束考试成功",1,null);
            Bind();
     },function(err){
              showMassgeBox("提示",err._message,1,null);
        });
}


//绑定方法  --------------------------------------------------------------绑定，高亮,弹出窗口 等其他方法区域
function Bind()
{
    document.getElementById('btnBind').click();
}

function Select()
{
    document.getElementById('txtYear').value = document.getElementById('selYear').value;
    document.getElementById('txtTerm').value = document.getElementById('selTerm').value;
    document.getElementById('txtGrade').value = document.getElementById('selGrade').value;
    document.getElementById('txtState').value = -1;//document.getElementById('selState').value;
    document.getElementById('btnSelect').click();
}

//弹出添加成绩窗口
function ShowAddWindow()
{
    var areaId = Number("<%=CommonScore.GetAreaID %>");
    if(areaId < 0)
    {
        showMassgeBox("提示","您没有操作局统考的权限",1,null);
        return false;
    }
    ShowPopForm("popTable", "formTitle", "新建局级考试");
    showMask();
}

 //关闭遮罩层
function CloseMask(formId)
{
    ClosePopForm(formId,true);
    hideMask();
}



//选中行高亮
function SetHightLight(obj)
{
    if(obj != null) 
        obj.style.backgroundColor = "#fffccf";
        
    var table = document.getElementById('eduExamTable');
    for(var i =0 ; i < table.rows.length;i++)
    {
        var row = table.rows[i];
        if(row != null && row.rowIndex != obj.rowIndex)
        {
            row.style.backgroundColor = "#ffffff";
        }
    }
}

//过滤学年
function FilterYearChange()
{
    var value = event.srcElement.value;
    document.getElementById('txtYear').value = value;
}
//过滤学期
function FilterTermChange()
{
    var value = event.srcElement.value;
    document.getElementById('txtTerm').value = value;
}
//过滤年级
function FilterGradeChange()
{
    var value = event.srcElement.value;
    document.getElementById('txtGrade').value = value;
}
//过滤状态
function FilterStateChange()
{
    var value = event.srcElement.value;
    document.getElementById('txtState').value = value;
}


//导入数据
function InputScore(row)
{
    window.showModalDialog("InputScore/Default.aspx?examid="+row.id+"&examtype=1");
}
function CheckAreaID(areaid)
{
    if(areaid < 1)
    {
        showMassgeBox("提示","您没有操作局统考的权限",1,null);
        return false;
    }
    return true;
}
</script>

</head>

<body onload="Load();">
    <form id="form1" runat="server">
      <div class="mainWarp" >
        <div class="pageBody"  style="height:96%;">
             <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
         </asp:ScriptManager>
            
       <%--             <input type='text' style="color:#4682B4; font-size:15px;border-right: 0px; border-top: 0px; padding-left: 0px; border-left: 0px; width: 500px; border-bottom: 0px" id="txtOpenExam" readonly/>--%>
                    <ul class="butList">
                        
                        <li>
                    学年：<select id="selYear" onclick="FilterYearChange();">
                               <%= CommonScore.GetSchoolYearOption()%>
                            </select>
                             <select id="selTerm" onclick="FilterTermChange();">
                                <option value="0">全部</option>
                                <option value="1">上学期</option>
                                <option value="2">下学期</option>
                            </select>
                            年级：
                             <select id="selGrade" onclick="FilterGradeChange();">
                                <option value="-1" selected="selected">全部</option>
                                <optgroup label="小学">
                                    <option value="1">一年级</option>
                                    <option value="2">二年级</option>
                                    <option value="3">三年级</option>
                                    <option value="4">四年级</option>
                                    <option value="5">五年级</option>
                                    <option value="6">六年级</option>
                                </optgroup>
                                <optgroup label="中学">
                                    <option value="7">初一</option>
                                    <option value="8">初二</option>
                                    <option value="9">初三</option>
                                </optgroup>
                                <optgroup label="高中">
                                     <option value="10">高一</option>
                                     <option value="11">高二</option>
                                     <option value="12">高三</option>
                                </optgroup>   
                            </select>
                             <!--状态：-->
                                <select id="selState" onclick="FilterStateChange();" style="display:none">
                                    <option value="-1" selected="selected">全部</option>
                                    <option value="0">新建</option>
                                    <option value="1">已下发</option>
                                </select>
                        </li>
                        <li><input type="button" value="查询" onclick="Select();" class="commonBut"  /></li>
                       <li><input type="button" id="btnCreateExam" style="visibility:hidden;" value="新建考试" onclick="if(parent.useManage){ShowAddWindow();}else{showMassgeBox('提示','没有权限新建考试',1,null);}"  class="commonBut" /></li>
                      </ul>
                     <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                         <ContentTemplate>
                         <div>
                             <asp:Repeater ID="Repeater1" runat="server">
                                <HeaderTemplate>
                                <div style="overflow-y:auto;overflow-x:none;height:98%;">
                                 <table id="eduExamTable" class="useList" style="width: 95%">
                                    <tr>
                                        <th style="text-align: left;padding-left: 5px;">考试名</th>
                                        <th style="text-align: left;padding-left: 5px;">状态</th>
                                        <th style="text-align: left;padding-left: 5px;">创建日期</th>
                                        <th style="text-align: left;padding-left: 5px;">学年学期</th>
                                        <th style="text-align: left;padding-left: 5px;">年级</th>
                                        <th style="text-align: left;padding-left: 5px;">分科</th>
                                        <th>打开考试</th>
                                        <th>查看已提交成绩学校</th>
                                        <th>操作列</th>
                                    </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <tr id="<%# Eval("RID") %>" style="background-color:<%#CommonScore.GetOpenExamColor(1,currentOpenEXAM,1,(int)Eval("RID")) %>">
                                        <td style="text-align: left;padding-left: 5px;"><%# Eval("Name") %></td>
                                        <td style="text-align: left;padding-left: 5px;"><%# ConvertState((int)Eval("State"))%></td>
                                        <td style="text-align: left;padding-left: 5px;"><%# ((DateTime)Eval("CreateDate")).ToShortDateString() %></td>
                                        <td style="text-align: left;padding-left: 5px;" id="<%# Eval("Term")%>" schoolYear="<%# Eval("SchoolYear")%>"><%# Eval("SchoolYear")%><%# ConvertTerm((short)Eval("Term"))%></td>
                                        <td style="text-align: left;padding-left: 5px;" id="<%# Eval("Grade")%>"><%# ConvertGrade((int)Eval("Grade"))%></td>
                                        <td style="text-align: left;padding-left: 5px;" id="<%# Eval("ClassType")%>"><%# ConvertClassType((int)Eval("ClassType"))%></td>
                                        <td><a><img src="<%# CommonScore.OpenExamSrc(1,1,currentOpenEXAM,(int)Eval("RID")) %>" alt="打开考试" class="imageBtnStyle" onclick="if(parent.useReport || parent.useManage){OpenEduExamWidow(this.parentElement.parentElement.parentElement);}else{showMassgeBox('提示','您没有权限使用这个功能！',1,null);}" /></a></td>
                                        <td><a><img src="../../Common/images/applySchool.png" alt="查看申报学校" class="imageBtnStyle" onclick="if(parent.useManage){ShowApplyWindow(this.parentElement.parentElement.parentElement)}"/></a></td>
                                        <td>
                                            <a><img src="../../Common/images/hadle_icon.gif" alt="修改" class="imageBtnStyle" allowUpdate="<%# Eval("State") %>" areaId="<%# Eval("AreaID")%>" onclick="if(!CheckAreaID(areaId)) return; if(this.allowUpdate==0 && parent.useManage){ShowUpdateWindow(this.parentElement.parentElement.parentElement);}else{showMassgeBox('提示','已下发或您没有权限使用这个功能！',1,null);}" /></a>
                                            <a><img alt="删除" class="imageBtnStyle" src="../../Common/images/delete.jpg" allowUpdate="<%# Eval("State") %>" areaId="<%# Eval("AreaID")%>"  onclick="if(!CheckAreaID(areaId)) return; if(this.allowUpdate==0 && parent.useManage){ShowDelWindow(this.parentElement.parentElement.parentElement);}else{showMassgeBox('提示','已下发或您没有权限使用这个功能！',1,null);}" /></a>
                                            <a><img alt="下发" class="imageBtnStyle" src="<%# CommonScore.PublishExamSrc((int)Eval("State"))%>" areaId="<%# Eval("AreaID")%>"  allowUpdate="<%# Eval("State") %>" onclick="if(!CheckAreaID(areaId)) return; if(this.allowUpdate==0 && parent.useManage){ShowPublishedWindow(this.parentElement.parentElement.parentElement);}"/></a>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                                <FooterTemplate>
                                    </table></div>
                                </FooterTemplate>
                              </asp:Repeater>
                              </div>                           
                         </ContentTemplate>
                         <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="btnBind" EventName="Click" />
                            <asp:AsyncPostBackTrigger ControlID="btnSelect" EventName="Click" />
                        </Triggers>
                     </asp:UpdatePanel>
                
                 <div style="display: none;">
                    <asp:Button ID="btnBind" runat="server" OnClick="btnBind_Click" Text="btnBind" />
                    <asp:Button ID="btnSelect" runat="server"   Text="查询" OnClick="btnSelect_Click" />
                    <asp:TextBox ID="txtYear" runat="server" />
                    <asp:TextBox ID="txtTerm" runat="server" />
                    <asp:TextBox ID="txtGrade" runat="server" />
                    <asp:TextBox ID="txtState" runat="server" />
                    <asp:TextBox ID="txtExamId" runat="server" />
                    <asp:TextBox ID="txtExamName" runat="server" />
                    <asp:TextBox ID="txtClassType" runat="server"/>
                </div>
                
                 <%-- 添加局级考试的弹出层 --%>
                 <div id="popTable" class="layoutWarp" style="display: none; width: 400px; overflow: inherit;">
                        <div class="title">
                            <span id="formTitle">新建考试</span> <a title="关闭" onclick="return CloseMask('popTable')">
                                关闭</a>
                        </div>
                         <iframe id="createExamFrame" width="100%" height="300px" src="CreateSituation.aspx" frameborder="0"></iframe>     
                     </div>
                
                <%-- 修改局级考试弹出层 --%>
                <div id="popTable2" class="layoutWarp" style="display: none; width: 400px; overflow: inherit;">
                        <div class="title">
                            <span id="formTitle2">修改考试</span> <a title="关闭" onclick="return CloseMask('popTable2')">
                                关闭</a>
                        </div>
                        <iframe id="updateExamFrame" width="100%" height="300px" src="UpdateSituation.aspx" frameborder="0"></iframe>
               </div>
               
                 <%-- 查看申报学校弹出层 --%>
                <div id="popTable3" class="layoutWarp" style="display: none; width: 400px; overflow: inherit;">
                        <div class="title">
                            <span id="formTitle3">查看已提交成绩学校</span> <a title="关闭" onclick="return CloseMask('popTable3')">
                                关闭</a>
                        </div>
                        <iframe id="applySchoolFrame" width="100%" height="300px" src="ViewApplySchool.aspx" frameborder="0"></iframe>
               </div>

            </div>
          </div>
      
    </form>
</body>
</html>